"use strict";

/**
 * author:Administrator
 * date:2015/11/30
 * desc: user face dao
 */
var Model = require('../model/face_rendered.js');
var dao = {};
var counter = require('./counter.js');
var myCounter = counter.bindCounter(counter.TypesEnum.faceRendered);
module.exports = dao;

/**
 * save
 * @param json {object}
 */
dao.save = function *(json) {
  var rfaceid = yield myCounter();
  var entity = new Model({
    rfaceid: rfaceid,
    uid: json.uid,
    ufaceid: json.ufaceid,
    partids: json.partids,
    url: json.path || '',
    rpath: json.rpath || '',
    success: +!!json.url
  });

  return yield entity.save();
};

dao.cleanCollection = function*() {
  return yield Model.remove({});
};